package data;

import java.io.Serializable;
import javax.persistence.*;

/**
 *
 * @author Michal Hanzlik, Tomas Jiran
 */
/*
 create table Komentar (
 id_komentare         INT4                 not null,
 id_filmu             INT4                 not null,
 id_osoby             INT4                 not null,
 text                 VARCHAR(1024)        null,
 constraint PK_KOMENTAR primary key (id_komentare)
 );
 */
@Entity
@Table(name = "komentar")
public class Komentar implements Serializable {

    /**
     * id_komentare INT4 not null,
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "komentar_id_komentare_seq")
    @Column(unique = true, nullable = false)
    private int id_komentare;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_osoby")
    private Uzivatel owner;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_filmu")
    private Film film;

    /**
     * text VARCHAR(1024) null,
     */
    @Column(columnDefinition = "varchar(1024)")
    private String text;

    public Komentar() {
    }

    public Komentar(int id_komentare, int id_filmu, int id_osoby) {
        this.id_komentare = id_komentare;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }

    public void setFilm(Film film) {
        this.film = film;
    }

    public Film getFilm() {
        return film;
    }

    public void setOwner(Uzivatel owner) {
        this.owner = owner;
    }

    public Uzivatel getOwner() {
        return owner;
    }

    @Override
    public String toString() {
        String s = this.getOwner().getLogin();
        s += ": ";
        s += this.getText();
        return s;
    }
}